home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / morse / staton / cpo_spk.txt < prev    next >
Text File  |  1994-04-22  |  10KB  |  524 lines

  1. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;
  2. ;   COPYRIGHT (C) 1994 KEN STATON    ;
  3. ;         ALL RIGHTS RESERVED        ;
  4. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;
  5.  
  6. #INCLUDE "GLOBALS.TXT"
  7.     .MSFIRST                ; MOST SIGNIFICANT BYTE FIRST!
  8.  
  9. ;
  10. ;       Ken Staton
  11. ;       Feb 9, 1993     First coding
  12. ;       Apr 3, 1993     Added DAC support
  13. ;               ~44K of digitized speech: 
  14. ;             A-Z = 26 + 0-9 = 10 + {.,?} = 3 total = 39
  15. ;             {sk,bt,ar,dn,kn} = 5; 39 + 5 = 44
  16. ;             could implement {sk,bt,ar,dn,kn} as 
  17. ;             concatenations of letters
  18. ;       Jun 3, 1993     Added ADPCM digitized speech
  19. ;    Aug 17, 1993    Cleanup.  Removed Debug & RS232.
  20. ;    Aug 25, 1993    Changed 4Mc->3.2768Mc
  21. ;            Fixed interrupt problem (not re-entrant)
  22. ;             by disabling INTS in speak & morse
  23. ;    Jan 25, 1994    Added BUILDIT speech mode in preparation
  24. ;             for allophone based speech.  Currently
  25. ;             used for concatenating sounds of prosigns.
  26. ;    Feb 1, 1994    Changed 3.2768Mc->6.0Mc to support 8KHz data rate.
  27. ;    Mar 19, 1994    Added SET Option. Commented out to disable.
  28. ;    Apr 16, 1994    Fixed char rate bug when changed from default.
  29. ;    Apr 20, 1994    Added programmed delay before and after speaking
  30. ;    Apr 22, 1994    Version 1.0
  31. ;
  32. ;---------------------------------------------------------------------
  33. ;
  34. ;    Select options using ext_int0
  35. ;    Options are:
  36. ;    Speed
  37. ;        5@16
  38. ;        13@18
  39. ;        20@23
  40. ;    Toggle
  41. ;        SPEECH
  42. ;    Random Chars
  43. ;    Random Groups of five chars
  44. ;    Sequence Chars
  45. ;    Toggle Set (see SUBSET; not enabled)
  46. ;        LETTERS
  47. ;        NUMBERS
  48. ;        PROSIGNS
  49. ;        PUNCTUATION
  50. ;**        PROGRESSIONS
  51. ;**        COMPLEMENTS
  52. ;    ** = not yet implemented...
  53. ;
  54. ;
  55.  
  56.  
  57.  
  58. #INCLUDE "ISR_INIT.TXT"
  59.  
  60.  
  61. ;**************************************************************
  62. ;
  63. ; MAIN LOOP
  64. ;
  65.  
  66. MAIN
  67.     CJNE    R4,#RAN,MODE0        ;if R4=Random then JMP RCHARS
  68.     LJMP    RCHARS
  69.  
  70. MODE0    CJNE    R4,#SEQ,MODE1        ;if R4=Sequence then JMP CYCLE
  71.     LJMP    CYCLE
  72.     
  73. MODE1    CJNE    R4,#GRP,MODE2        ;if R4=Group then JMP RGRP
  74.     LJMP    RGRP
  75.  
  76. MODE2    SJMP    MAIN
  77.  
  78. ;**************************************************************
  79. ;
  80. ; RCHARS - Random Characters
  81. ;
  82.     
  83. RCHARS
  84.     LCALL    RANDOM            ; GENERATE RANDOM INDEX
  85. TRUNC    MOV    A,PH
  86.     RR    A
  87.     RR    A
  88.     RR    A
  89.     MOV    COUNT,A            ; SAVE INDEX
  90.     CLR    C
  91.     SUBB    A,#SETSIZE        ; A <- A - C - #data
  92.     JNC    RCHARS            ; C=0 -> A>=SETSIZE
  93.                     ; for INDEX: 0..SETSIZE-1
  94.     MOV    A,COUNT
  95.     LCALL    SUBSET
  96.     JZ    RCHARS
  97.  
  98.     JNB    CODE,RCPO1
  99.     MOV    A,COUNT            ; restore index
  100.     LCALL   MORSE            ; sound code
  101.  
  102. RCPO1
  103.     JNB    SPEAK,RCPO2
  104.     MOV     A,COUNT                    ; restore index
  105.     LCALL   SPEECH            ; speak code
  106.  
  107. RCPO2
  108.     LJMP    MAIN            ; RESTART MAIN LOOP
  109.  
  110. ;**************************************************************
  111. ;
  112. ; RGRP - Random Groups
  113. ;
  114.  
  115. RGRP
  116.     PUSH    RH
  117.     PUSH    RL
  118.  
  119.     LCALL    RCODE
  120.     LCALL    RCODE
  121.     LCALL    RCODE
  122.     LCALL    RCODE
  123.     LCALL    RCODE
  124.  
  125.     LCALL    WORD_DLY
  126.  
  127.     POP    RL        ; Restore seed. psuedorandom,
  128.     POP    RH        ; so sequence will be the same...
  129.  
  130.     LCALL    RTALK
  131.     LCALL    RTALK
  132.     LCALL    RTALK
  133.     LCALL    RTALK
  134.     LCALL    RTALK
  135.  
  136.     LJMP    MAIN        ; RESTART MAIN LOOP
  137.  
  138. ;**************************************************************
  139. ;
  140. ; RCODE - Random Code SUBROUTINE for RGRP
  141. ;
  142.  
  143. RCODE    LCALL    RANDOM            ; GENERATE RANDOM INDEX
  144.     MOV    A,PH
  145.     RR    A
  146.     RR    A
  147.     RR    A
  148.     MOV    COUNT,A            ; SAVE INDEX
  149.     CLR    C
  150.     SUBB    A,#SETSIZE
  151.     JNC    RCODE            ;C=0 -> A>=SETSIZE
  152.                     ; for INDEX: 0..43
  153.                     ; for INDEX: 0..SETSIZE-1
  154.     MOV    A,COUNT
  155.     LCALL    SUBSET
  156.     JZ    RCODE
  157.  
  158.     MOV    A,COUNT            ; RESTORE INDEX
  159.     LCALL   MORSE            ; sound code
  160.     RET                ; DONE
  161.  
  162. ;**************************************************************
  163. ;
  164. ; RTALK - Random Talk SUBROUTINE for RGRP
  165. ;
  166.  
  167. RTALK    LCALL    RANDOM            ; GENERATE RANDOM INDEX
  168.     MOV    A,PH
  169.     RR    A
  170.     RR    A
  171.     RR    A
  172.     MOV    COUNT,A            ; SAVE INDEX
  173.     CLR    C
  174.     SUBB    A,#SETSIZE
  175.     JNC    RTALK            ; C=0 -> A>=SETSIZE
  176.                     ; for INDEX: 0..SETSIZE-1
  177.     MOV    A,COUNT
  178.     LCALL    SUBSET
  179.     JZ    RTALK
  180.  
  181.     MOV    A,COUNT            ; RESTORE INDEX
  182.     JNB    SPEAK,RTDONE
  183.     LCALL   SPEECH            ; speak code
  184.  
  185. RTDONE
  186.     RET                ; DONE
  187.  
  188. ;**************************************************************
  189. ;
  190. ; CYCLE - Cycle sequentially through character set
  191. ;
  192.  
  193. CYCLE
  194.     MOV     COUNT,#0
  195. NEXT_C  MOV     A,COUNT
  196.     LCALL    SUBSET
  197.     JZ    NEXT_C
  198.  
  199.     MOV    A,COUNT
  200.     JNB    CODE,CYC1
  201.     LCALL   MORSE            ; sound code
  202.  
  203. CYC1
  204.     JNB    SPEAK,CYC2        ; test if speak on
  205.     MOV     A,COUNT                    ; restore index
  206.     LCALL   SPEECH            ; speak code
  207.  
  208. CYC2
  209.     INC     COUNT
  210.     MOV    A,COUNT
  211.     CJNE    A,#SETSIZE,NEXT_C
  212.     LJMP    MAIN            ; RESTART MAIN LOOP
  213.  
  214.  
  215.  
  216. ;
  217. ;*************************************************************************
  218. ;
  219. ; RANDOM
  220. ;
  221. ; RANDOM NUMBERS BETWEEN 0 AND {26+10+3+4 = 43}-1 = 42
  222. ; i.e. mod 42
  223. ;
  224. ; Best bet is to generate seed by having 16 bit counter that
  225. ; increments until input at power up...this requires setting
  226. ; mode, or maybe just indicating when to start...
  227. ; Some external asyncronous event must establish seed.
  228. ;   See EXT0 in INIT_ISR.
  229. ;
  230. ; Algorithm described in:
  231. ; The Art of Computer Programming Volume 2, Seminumerical Algorithms
  232. ;   Donald Knuth
  233. ;
  234. ; X <- (aX + c) mod m
  235. ;
  236. ; m = 65536
  237. ; c/m ~ 0.2113248654
  238. ; c odd
  239. ; 13.85 -> c = 13
  240. ; a > sqrt(m), a > m/100, a < m - sqrt(m)
  241. ; 256 < 655 < a < 65280
  242. ; a = 31415    {= 122*256 + 183}
  243. ;
  244. ; X <- (31415 * X + 13) mod 65536
  245. ;
  246. ; NOTE: that the arithmetic done in a 16 bit word
  247. ; is mod 2^16 = 65536
  248. ;
  249. ; A * B = (AL + 2^8 * AH) * (BL + 2^8 * BH)
  250. ;       = AL * BL + 2^8(AL * BH + AH * BL) + 2^16(AH * BH)
  251. ; A * 31415 = AL * 183 + 2^8(AL * 122 + AH * 183) + 2^16(AH * 122)
  252.  
  253. RANDOM
  254.     MOV    A,RL
  255.     MOV    B,#183
  256.     MUL    AB        ; A[7..0],B[15..8] product bits
  257.     MOV    PL,A
  258.     MOV    PH,B
  259.  
  260.     MOV    A,RL
  261.     MOV    B,#122
  262.     MUL    AB
  263.     ADD    A,PH
  264.     MOV    PH,A
  265.  
  266.     MOV    A,RH
  267.     MOV    B,#183
  268.     MUL    AB
  269.     ADD    A,PH
  270.     MOV    PH,A
  271.  
  272.     CLR    C            ; NOW ADD c
  273.     MOV    A,PL
  274.     ADDC    A,#13
  275.     MOV    PL,A    
  276.     JNC    NOCARRY
  277.     INC    PH
  278. NOCARRY
  279.     MOV    RL,PL
  280.     MOV    RH,PH    
  281.     RET                ; DONE RANDOM
  282.  
  283. ;
  284. ;*************************************************************************
  285. ;
  286. ; Define code for MORSE SUBROUTINE
  287. ;
  288. ;
  289. ; numbers 5 bits
  290. ; punctuation 6 bits
  291. ; letters <= 4 bits
  292. ;
  293. ; b7  b6  b5    |   b[4:0] -> group
  294. ;---------------|--------------------------
  295. ;  0  0  d      |   number or prosign
  296. ;  0  1  d      |   punctuation or prosign
  297. ;  1  0  0      |   1 element letter
  298. ;  1  0  1      |   2 element letter
  299. ;  1  1  0      |   3 element letter
  300. ;  1  1  1      |   4 element letter
  301. ;        | 
  302. ; d => don't    | 1 => dah
  303. ;    care    | 0 => dit
  304.  
  305. CODE_TBL
  306.  
  307. LETTERS
  308. MCA .DB 10100001B
  309. MCB .DB 11101000B
  310. MCC .DB 11101010B
  311. MCD .DB 11000100B
  312. MCE .DB 10000000B
  313. MCF .DB 11100010B
  314. MCG .DB 11000110B
  315. MCH .DB 11100000B
  316. MCI .DB 10100000B
  317. MCJ .DB 11100111B
  318. MCK .DB 11000101B
  319. MCL .DB 11100100B
  320. MCM .DB 10100011B
  321. MCN .DB 10100010B
  322. MCO .DB    11000111B
  323. MCP .DB 11100110B
  324. MCQ .DB 11101101B
  325. MCR .DB 11000010B
  326. MCS .DB 11000000B
  327. MCT .DB 10000001B
  328. MCU .DB 11000001B
  329. MCV .DB 11100001B
  330. MCW .DB 11000011B
  331. MCX .DB 11101001B
  332. MCY .DB 11101011B
  333. MCZ .DB 11101100B
  334.  
  335. NUMBERS
  336. MC1 .DB 00001111B
  337. MC2 .DB 00000111B
  338. MC3 .DB 00000011B
  339. MC4 .DB 00000001B
  340. MC5 .DB 00000000B
  341. MC6 .DB 00010000B
  342. MC7 .DB 00011000B
  343. MC8 .DB 00011100B
  344. MC9 .DB 00011110B
  345. MC0 .DB 00011111B
  346.  
  347. PUNCTUATION
  348. MCPP .DB 01010101B
  349. MCPC .DB 01110011B
  350. MCPQ .DB 01001100B
  351.  
  352. PROSIGNS
  353. MCSDN .DB 00010010B
  354. MCSSK .DB 01000101B
  355. MCSBT .DB 00010001B
  356. MCSAR .DB 00001010B
  357. MCSKN .DB 00010110B        ; <<< NOT PART OF TEST SET!
  358.  
  359.  
  360. SUBSET
  361. ;
  362. ; CHECKS IF CHARACTER INDEX IS IN AN ENABLED SUBSET
  363. ; RETURNS ACC=0 IF NOT ENABLED
  364. ; RETURNS ACC=1 IF ENABLED
  365. ;
  366. ;    CLR    C        
  367. ;    SUBB    A,#CONST    ; C=0 -> A>=CONST
  368. ;
  369. ;    CLR    C
  370. ;    SUBB    A,#26        ; A={0..25} -> LETTER
  371. ;    JC    IN_GL        ; C=1 -> A<26
  372. ;    MOV    A,COUNT
  373. ;    SUBB    A,#36        ; A={26..35} -> NUMBER    
  374. ;    JC    IN_GN        ; C=1 -> 26<=A<36
  375. ;    MOV    A,COUNT
  376. ;    SUBB    A,#39        ; A={36..38} -> PUNCTUATION
  377. ;    JC    IN_GP        ; C=1 -> 36<=A<39
  378. ;    MOV    A,COUNT
  379. ;    SUBB    A,#43        ; A={39..42} -> PRO-SIGN
  380. ;    JC    IN_GS        ; C=1 -> 39<=A<43
  381. ;IN_GL
  382. ;    JNB    GL,NOT_IN_SET
  383. ;    MOV    A,#YES
  384. ;    RET
  385. ;IN_GN
  386. ;    JNB    GN,NOT_IN_SET
  387. ;    MOV    A,#YES
  388. ;    RET
  389. ;IN_GP
  390. ;    JNB    GP,NOT_IN_SET
  391. ;    MOV    A,#YES
  392. ;    RET
  393. ;IN_GS
  394. ;    JNB    GS,NOT_IN_SET
  395. ;    MOV    A,#YES
  396. ;    RET
  397. ;NOT_IN_SET
  398. ;    MOV    A,#NO
  399. ;    RET
  400.  
  401.     MOV    A,#YES        ; always enabled for now...
  402.     RET
  403.  
  404. SPEECH
  405. ;
  406. ; INPUT ACC = index for sound table, which must match
  407. ;         order of code table
  408.  
  409.  
  410.     CLR    C
  411.     RLC    A        ;MUL BY 2 for 2 byte address entries in table
  412.     MOV    TMP2,A        ;save index by 2
  413.     MOV    DPTR,#SOUND_TBL
  414.  
  415.     MOVC    A,@A+DPTR
  416.     MOV    ADDR_H,A    ;save addrh
  417.  
  418.     MOV    A,TMP2        ;restore index by 2
  419.     INC    A        ;get rest of addr
  420.     MOVC    A,@A+DPTR
  421.     MOV    DPL,A
  422.     MOV    DPH,ADDR_H
  423. ;
  424. ; delay after code - before speaking
  425. ;
  426.     MOV    R7,DLY_B4
  427.     LCALL    DELAY
  428.     MOV    R7,DLY_B4
  429.     LCALL    DELAY
  430.     MOV    R7,DLY_B4
  431.     LCALL    DELAY
  432.     MOV    R7,DLY_B4
  433.     LCALL    DELAY
  434.  
  435.     MOV    TMP2,#0        ;start at entry 0
  436.  
  437. BLD_LOOP    
  438.     MOV    A,TMP2
  439.     MOVC    A,@A+DPTR
  440.     
  441.     CJNE    A,#PA1,TP2    ;test if 1mS pause
  442.     SJMP    PAUSE1
  443. TP2    CJNE    A,#PA10,TP3    ;test if 10mS pause
  444.     SJMP    PAUSE2
  445. TP3    CJNE    A,#PA100,TP4    ;test if 100mS pause
  446.     SJMP    PAUSE3
  447. TP4    CJNE    A,#PA300,TP5    ;test if 500mS pause
  448.     SJMP    PAUSE4
  449. TP5    CJNE    A,#PA500,TTERM    ;test if terminator (0FFH)
  450.     SJMP    PAUSE5
  451. TTERM    CJNE    A,#0FFH,BLD_MORE
  452. ;
  453. ; delay after speaking - before next code
  454. ;
  455.     MOV    R7,DLY_AR
  456.     LCALL    DELAY
  457.     MOV    R7,DLY_AR
  458.     LCALL    DELAY
  459.     MOV    R7,DLY_AR
  460.     LCALL    DELAY
  461.     MOV    R7,DLY_AR
  462.     LCALL    DELAY
  463.     RET            ; DONE
  464.  
  465.  
  466. BLD_MORE
  467.     LCALL    MAKESOUND
  468. BMORE    INC    TMP2
  469.     SJMP    BLD_LOOP
  470.  
  471.  
  472. ;
  473. ; These pauses are used in speech concatenation
  474. ;
  475.     
  476. PAUSE1
  477.     MOV    R7,#1
  478.     LCALL    DELAY
  479.     SJMP    BMORE
  480.  
  481. PAUSE2
  482.     MOV    R7,#10
  483.     LCALL    DELAY
  484.     SJMP    BMORE
  485.  
  486. PAUSE3
  487.     MOV    R7,#100
  488.     LCALL    DELAY
  489.     SJMP    BMORE
  490.  
  491. PAUSE4
  492.     MOV    R7,#150
  493.     LCALL    DELAY
  494.     MOV    R7,#150
  495.     LCALL    DELAY
  496.     SJMP    BMORE
  497.  
  498. PAUSE5
  499.     MOV    R7,#250
  500.     LCALL    DELAY
  501.     MOV    R7,#250
  502.     LCALL    DELAY
  503.     SJMP    BMORE
  504.  
  505. SOUND_TBL
  506. #INCLUDE "TABLE02.TXT"        ; Defines contatenations
  507.  
  508. MAKESOUND
  509. #INCLUDE "SPEAK.TXT"
  510.  
  511. MORSE
  512. #INCLUDE "MORSE.TXT"
  513.  
  514.  
  515.     .ORG    (0FFFFH-51)
  516.     .TEXT    "COPYRIGHT (C) 1994 KEN STATON. ALL RIGHTS RESERVED"
  517.  
  518.     .ORG    0FFFFH
  519.     .DB    0FFH
  520.     .END
  521.